package com.example.alee.mybatis.springmybatis.mapper;

import com.example.alee.mybatis.springmybatis.po.Article;
import com.example.alee.mybatis.springmybatis.po.ArticleDetail;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

/**
 * 一对一查询
 */
public interface ArticleOneMapper {


    //查询文章详情
    @Select("""
                select id,article_id,content from article_detail where article_id = #{articleId}
            """)
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "article_id", property = "articleId"),
            @Result(column = "content", property = "content")
    })
    ArticleDetail selectArticleDetail(Integer articleId);


    //查询文章的属性包含详情（内容）
    @Select("""
                select  id, user_id, title, summary, read_count, create_time, update_time  from article where id = #{id}
            """)
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "summary", property = "summary"),
            @Result(column = "read_count", property = "read_count"),
            @Result(column = "create_time", property = "create_time"),
            @Result(column = "update_time", property = "update_time"),
            @Result(column = "id", property = "articleDetail",
                    one = @One(select = "com.example.alee.mybatis.springmybatis.mapper.ArticleOneMapper.selectArticleDetail",
                            fetchType = FetchType.LAZY)
            )
    })

    Article selectAllArticle(Integer id);

}
